package com.sun.config;


import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class DataSourceAop {

    @Pointcut("@annotation(com.sun.annotation.Master)")
    public void master() {
    }

    @Pointcut("@annotation(com.sun.annotation.Slave)")
    public void salve() {
    }


    @Before("master()")
    public void setMasterDataSource() {
        log.info("数据源切换成master");
        DataSourceType.setDataBaseType(DataSourceType.DataBaseType.MASTER);
    }

    @Before("salve()")
    public void setSlaveDataSource() {
        log.info("数据源切换成slave");
        DataSourceType.setDataBaseType(DataSourceType.DataBaseType.SLAVE);
    }
}
